<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
    <div id="app">
      <h1>{{title}}</h1>
      <button @click="getChild">调用子组件的方法</button>
      <child ref="xc"></child>
    </div>
	</body>
  <script src="../vue.js"></script>
  
  <template id="temp1">
    <div>
      <p>这是子组件</p>
      <button @click="$parent.add()">这是子组件的按钮</button>
      <button @click="fn()">这是子组件的按钮</button>
      <p>{{$parent.title}}</p>
    </div>
  </template>
  
  <script>
    
    let temp1 = {
      template: "#temp1",
      methods:{
        fn(){
          console.log("这是子组件")
          this.$parent.add();
        }
      }
    }
    
    var vm = new Vue({
      el:"#app",
      data:{
        title:"hello vue"
      },
      methods:{
        add(){
          this.title += " child"
        },
        getChild(){
          this.$refs.xc.fn();
        }
      },
      components:{
        child:temp1
      }
    })
    
  </script>
</html>
